<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>欢迎来到后台</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="icon" href="__PUBLIC__/Images/favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="__PUBLIC__/Images/favicon.ico" type="image/x-icon" />
        <TYcss file="index"/>
        <TYcss file="jquery.ui.min" public="true"/>
        <TYjs file="jquery-1.11.1.min,jquery.min,jquery.ui.min,utils,common" public="true"/>
        <TYimport plugin="artDialog"/>
        <TYjs file='common'/>
        <!-- 下面的Css用来隐藏后台页面的调试div，不遮挡框架页面的调试div -->
        <style type="text/css">
            #think_page_trace,#think_page_trace_open{display:none;}
        </style>
    </head>
    <body onresize="resetHeight();">
        <div id="top" class="js_top">
            <div class="top_sidebar clearFix">
                <ul>
                    <li>您好！&nbsp;{$Think.session.username}</li>
                    <!-- <li><a class="js_menu_list" href="{:U('Admin/edit_info','',false,false,false)}">修改资料</a></li>
                    <li><a target="_blank" href="{:U('Home/', '', false, false, true)}">电脑版</a></li>
                    <li><a target="_blank" href="{:U('Mobile/', '', false, false, true)}">手机版</a></li> -->
                    <li><a class="js_tologout" href="{:U('Admin/logout','',false,false,false)}">退出</a></li>
                </ul>
            </div>
            <div class="top_tool">
                <div id="logo"></div>
                <ul class="tool_btn">
                    <li><a  class="js_tool" href="javascript:;" group_id="-1">系统信息</a></li>
                    <foreach name="menuList" item="voGroup">
                        <li><a class="js_tool" group_id="{$key}" href="javascript:;">{$voGroup.name}</a></li>
                    </foreach>
                </ul>
                <a class="update_cache" href="javascript:clearCache();">清除缓存</a>
            </div>
        </div>
        <div id="main">
            <a class="open_close shadow js_open_and_close" href="javascript:;" ></a>
            <div class="menu_sidebar shadow js_menusidebar">
                <foreach name="menuList" item="voGroup">
                    <ul class="group_menu" group_id="{$key}">
                        <foreach name="voGroup['child']" item="voClass">
                            <li class="submenu_title">{$voClass.name}</li>
                            <foreach name="voClass['child']" item="vo">
                                <if condition="$vo['is_show'] eq 1">
                                    <li class="submenu_list">
                                        <a class="js_menu_list" href="{:U($vo['operation'],'',false,false,false)}">{$vo.name}</a>
                                    </li>
                                </if>
                            </foreach>
                        </foreach>
                    </ul>
                </foreach>
            </div>
            <div id="content" style="overfloat">
                <iframe id="right_main" scrolling="auto" frameborder="false" allowtransparency="true" style="border: medium none; width: 100%;height: 100%;" src="" name="right"></iframe>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        var iframeUrl = "{$iframeSrc}"; //内联框架URL
        var mObj = $('#main .js_menusidebar'); //菜单
        var aObj = $('#main a.js_open_and_close'); //隐藏按钮
        var IObj = $('#right_main'); //内联框架
        var main = $('#main');
        var topH = $('.js_top').height(); //头部菜单高度
        var toolObj = $('.js_tool'); //工具栏a标签
        var toolAObj = $('.js_tool.active'); //激活的工具栏a标签
        var menuWidth = 170; //菜单宽度
        var group_id = "";//cookie中的分组id

        //修改全局语言
        $("#select_lang").selectmenu({
            change: function (event, data) {
                $(this).tyAjax({
                    isForm: false,
                    url: "{:U(GROUP_NAME.'/Language/select_langs')}",
                    data: {'lang_code': data.item.value},
                    beforeSend: function () {
                        loadding(langjs.change_lang);
                    },
                    callBack: function (data) {
                        if (data.status > 0) {
                            window.location.reload();
                        }
                    }
                });
            }
        });

        //刷新后自动加载
        IObj.attr('src', iframeUrl);
        group_id = Utils.getCookie('group_id');
        if (group_id == "" || group_id == "undefined" || group_id == undefined) {
            Utils.setCookie('group_id', -1, 1);
        } else {
            changeGroupMenu(group_id);
        }

        //工具栏
        toolObj.ready(function () {
            //重新获取分组id
            group_id = Utils.getCookie('group_id');
            //根据分组id添加active样式
            $('.js_tool[group_id=' + group_id + ']').addClass('active');
        }).click(function () {
            toolObj.removeClass('active');
            $(this).addClass('active');
            //当前点击分组的group_id
            var attrId = $(this).attr('group_id');
            changeGroupMenu(attrId);
            //重新设置cookie
            Utils.setCookie('group_id', attrId, 1);
            if (attrId == "-1") {
                openAndClose(false);
                //显示系统信息
                var url = '{:U("Admin/Index/sys_msg")}';
                IObj.attr('src', url);
            } else {
                openAndClose(true);
            }
        });

        //切换菜单
        function changeGroupMenu(group_id) {
            if (group_id != "-1") {
                $('.group_menu').removeClass('on');
                $('.group_menu[group_id=' + group_id + ']').addClass('on');
            }
        }

        //隐藏和显示菜单
        aObj.ready(function () {
            if (group_id !== "-1") {
                mObj.css('width', menuWidth).addClass('r_shadow');
                aObj.removeClass('r_shadow active_close').attr('title', '点击隐藏菜单');
            } else {
                aObj.addClass('r_shadow active_close').attr('title', '点击显示菜单');
            }
        }).click(function () {
            if (aObj.hasClass('r_shadow')) {
                openAndClose(true);
            } else {
                openAndClose(false);
            }
        });

        // 菜单显示隐藏
        //true 显示 false 隐藏
        function openAndClose(status) {
            //停止当前动画
            mObj.stop();
            if (status) {
                aObj.removeClass('r_shadow active_close').attr('title', '点击隐藏菜单');
                mObj.animate({width: menuWidth}, 800);
            } else {
                aObj.addClass('r_shadow active_close').attr('title', '点击展示菜单');
                mObj.animate({width: '0'}, 800);
            }
        }

        //子菜单点击
        $('.js_menu_list').click(function (e) {
            changeIframe($(this), e);
        });
        //修改内联框架url
        function changeIframe(obj, e) {
            e.preventDefault();
            e.stopPropagation();
            var url = 'http://' + document.domain + obj.attr('href');
            IObj.attr('src', url);
        }

        resetHeight();
        //重置高度
        function resetHeight() {
            //屏幕-顶部的高度
            var vH = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - topH;
            main.height(vH);
        }

        //退出
        $(".js_tologout").click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            logout_url = $(this).attr('href');
            art.dialog.confirm('退出登录', function () {
                window.location.href = logout_url;
            });
        });

        //清除缓存
        function clearCache() {
            loadding('系统正在清理缓存文件，请稍候...');
            $.get('{:U("Admin/Index/clear_cache")}', function (result) {
                unloadding();
                icon = result.status == 1 ? 'succeed' : 'error';

                art.dialog({
                    "icon": icon,
                    "title": '消息',
                    "id": "loadding",
                    "lock": true,
                    "fixed": true,
                    "drag": false
                }).content(result.info);

                var interval = setInterval(function () {
                    clearInterval(interval);
                    window.location.reload();
                }, 1000);
            });
        }
    </script>
</html>
